# No.3 1h17m
def main():
    people = list(map(int, input().split()))
    n = len(people)
    if n > 30000: # 超出30000，输入异常
        print(-1)
        return
    if n < 2: # 如果人数为0，1
        print(n)
        return
    if sum(people) == 0:
        print(0)
        return
    
    for i in range(n):
        if people[i] < 0: # 当people[i]为负数，向左进行战斗
            a = people[i]
            if i-1 < 0:
                break
            for j in range(i-1, -1, -1):
                if people[j] + a >= 0:
                    people[j] = people[j] + a
                    a = 0
                else:
                    a += people[j]
                    people[j] = 0
            people[i] = a        
    
    # 当战斗结束，不为0的就是幸存者
    ans = 0
    for p in people:
        if p != 0:
            ans += 1
    print(ans)        

if __name__ == "__main__":
    main()
    
###
### 官方答案
###
def asteroidCollision(people: list[int]) -> int:
    survivors = []
    for person in people:
        if person == 0:
            return -1
        alive = True
        # 当前人向左逃生，且有人向右逃生时进行决斗
        while alive and person < 0 and survivors and survivors[-1] > 0:
            # 决斗结果：当前人战斗力大于对手
            alive = survivors[-1] < - person
             # 如果战斗力相等或当前人战斗力更大，移除对手
            if survivors[-1] <= -person:
                person = person + survivors[-1] 

                survivors.pop()
            else:
                survivors[-1] = survivors[-1] + person
                print(survivors[-1])
        # 如果当前人仍然存活，将其添加到逃生者列表
        if alive:
            survivors.append(person)
    return len(survivors)

try:
    # 从输入获取人员列表
    people = list(map(int, input().split()))

    # 检查输入是否异常
    if len(people) > 30000:
        raise ValueError("输入异常")

    # 调用函数并输出结果
    result = asteroidCollision(people)
    print(result)
except ValueError as e:
    print(-1)